package init;

import objects.CarBase;
import objects.CarNodeStore;

import java.util.List;

/**
 * @author whn
 * 该类初始化一个车辆关系网，用于标识车与车之间的关系
 * 具有连接性的为1，不具有连接性的为0。
 */
public class InitCarRelation {
    public static void init(CarNodeStore carNodeStore) {
        List<CarBase> list = carNodeStore.getCarList();
        int[][] relation = carNodeStore.getRelation();
        double[][] distance = carNodeStore.getDistance();
        double x1, x2;
        double y1, y2;
        double x, y, dis;
        for (int i = 0; i < list.size(); i++) {
            for (int j = 0; j < list.size(); j++) {
                x1 = list.get(i).getX();
                y1 = list.get(i).getY();
                x2 = list.get(j).getX();
                y2 = list.get(j).getY();
                x = x1 - x2;
                y = y1 - y2;
                dis = Math.sqrt(x * x + y * y);
                distance[i][j] =dis;
                if (dis <= 250) {
                    relation[i][j] = 1;
                } else {
                    relation[i][j] = 0;
                }
            }
        }
        carNodeStore.setRelation(relation);
    }
}
